﻿<%@ WebHandler Language="C#" Class="UpdatePrice" %>

using System;
using System.Web;
using System.Collections;
using System.Collections.Generic;
using Newtonsoft.Json;
using System.Data.Linq;
using System.Linq;
using System.Web;
using LdExpress;
using System.Data;
public class UpdatePrice : IHttpHandler, System.Web.SessionState.IRequiresSessionState
{

    public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "text/plain";
        int nPermissions = 0;
        if (context.Session["logined_id"] != null)
        {
            if (context.Session["PriceAreas"] != "") nPermissions = int.Parse(context.Session["PriceAreas"].ToString());
        }
        if (!(nPermissions > 3))
        {
            context.Response.Write(JsonConvert.SerializeObject("access denied!"));
        }
        if (context.Request.QueryString["acc"] != null)
        {
            var action = context.Request.QueryString["acc"].ToString().ToLower();
            switch (action)
            {
                case "priceareas":
                    UpdatePriceAreaNew(context);
                    break;
                case "truckerprice":
                    UpdateTruckerPrice(context);
                    break;
                default:
                    UpdatePriceAreaOld(context);
                    break;
            }
        }

    }
    private void UpdatePriceAreaOld(HttpContext context)
    {
        //Price Area OLD
        string items = context.Request.Params["items"];
        if (!string.IsNullOrEmpty(items))
        {
            List<LdExpress.PriceAreas> udpitems = JsonConvert.DeserializeObject<List<LdExpress.PriceAreas>>(items);
            string ids = "";



            ids = string.Join(",", udpitems.Select(q => q.ID));
            System.Data.DataSet ds = new System.Data.DataSet();
            string condition = "";
            if (!string.IsNullOrEmpty(ids))
            {
                condition = " and tbl_priceAreas.ID in (" + ids + ")";
            }
            else
            {
                context.Response.Write(JsonConvert.SerializeObject("not valid"));
            }
            int nNumOfPages = 0;
            LdExpress.PriceAreas.GetList(condition, "", "", 999, 1, out nNumOfPages, out ds, LdExpress.GV.cn, LdExpress.GV.trans);
            Array arr = udpitems.ToArray();
            int i = 0;
            if (ds.Tables.Count > 0)
            {
                LdExpress.PriceAreas price = new LdExpress.PriceAreas();
                LdExpress.PriceAreas newprice = new LdExpress.PriceAreas();
                string ex = "_" + context.Session["logined_user"] + ": " + DateTime.Now.ToString("dd-MM-yyyy");
                bool ischanged = false;
                foreach (System.Data.DataRow dr in ds.Tables[0].Rows)
                {
                    price = new LdExpress.PriceAreas();

                    if (!dr.IsNull("ID")) price.ID = long.Parse(dr["ID"].ToString());
                    if (!dr.IsNull("DC20")) price.DC20 = dr["DC20"].ToString();
                    if (!dr.IsNull("DC40")) price.DC40 = dr["DC40"].ToString();
                    if (!dr.IsNull("HC40")) price.HC40 = dr["HC40"].ToString();
                    if (!dr.IsNull("RF20")) price.RF20 = dr["RF20"].ToString();
                    if (!dr.IsNull("RF40")) price.RF40 = dr["RF40"].ToString();
                    if (!dr.IsNull("Validity")) price.Validity = dr["Validity"].ToString();
                    if (!dr.IsNull("Note")) price.Note = dr["Note"].ToString();
                    if (!dr.IsNull("CarrID")) price.CarrID = long.Parse(dr["CarrID"].ToString());
                    if (!dr.IsNull("PolID")) price.PolID = long.Parse(dr["PolID"].ToString());
                    if (!dr.IsNull("PodID")) price.PodID = long.Parse(dr["PodID"].ToString());
                    if (!dr.IsNull("ServiceAreaID")) price.ServiceAreaID = long.Parse(dr["ServiceAreaID"].ToString());
                    if (!dr.IsNull("Sort")) price.Sort = int.Parse(dr["Sort"].ToString());
                    if (!dr.IsNull("UserID")) price.UserID = int.Parse(dr["UserID"].ToString());
                    if (!dr.IsNull("LastUpdate")) price.LastUpdate = DateTime.Parse(dr["LastUpdate"].ToString());

                    //set new value
                    newprice = udpitems.Where(q => q.ID == price.ID).FirstOrDefault();

                    if (newprice != null)
                    {
                        newprice.DC20 = HttpUtility.HtmlDecode(newprice.DC20);
                        if ((newprice.DC20 != "") && (newprice.DC20 != price.DC20.Split('_')[0]))
                        {
                            price.DC20 = newprice.DC20 + ex;
                            ischanged = true;
                        }
                        else if (newprice.DC20 == "")
                        {
                            price.DC20 = newprice.DC20;
                            ischanged = true;
                        }
                        newprice.DC40 = HttpUtility.HtmlDecode(newprice.DC40);
                        if ((newprice.DC40 != "") && (newprice.DC40 != price.DC40.Split('_')[0]))
                        {
                            price.DC40 = newprice.DC40 + ex;
                            ischanged = true;
                        }
                        else if (newprice.DC40 == "")
                        {
                            price.DC40 = newprice.DC40;
                            ischanged = true;
                        }

                        newprice.HC40 = HttpUtility.HtmlDecode(newprice.HC40);
                        if ((newprice.HC40 != "") && (newprice.HC40 != price.HC40.Split('_')[0]))
                        {
                            price.HC40 = newprice.HC40 + ex;
                            ischanged = true;
                        }
                        else if (newprice.HC40 == "")
                        {
                            price.HC40 = newprice.HC40;
                            ischanged = true;
                        }

                        newprice.RF20 = HttpUtility.HtmlDecode(newprice.RF20);
                        if ((newprice.RF20 != "") && (newprice.RF20 != price.RF20.Split('_')[0]))
                        {
                            price.RF20 = newprice.RF20 + ex;
                            ischanged = true;
                        }
                        else if (newprice.RF20 == "")
                        {
                            price.RF20 = newprice.RF20;
                            ischanged = true;
                        }

                        newprice.RF40 = HttpUtility.HtmlDecode(newprice.RF40);
                        if ((newprice.RF40 != "") && (newprice.RF40 != price.RF40.Split('_')[0]))
                        {
                            price.RF40 = newprice.RF40 + ex;
                            ischanged = true;
                        }
                        else if (newprice.RF40 == "")
                        {
                            price.RF40 = newprice.RF40;
                        }

                        newprice.Validity = HttpUtility.HtmlDecode(newprice.Validity);
                        if ((newprice.Validity != "") && (newprice.Validity != price.Validity.Split('_')[0]))
                        {
                            price.Validity = newprice.Validity + ex;
                            ischanged = true;
                        }
                        else if (newprice.Validity == "")
                        {
                            price.Validity = newprice.Validity;
                            ischanged = true;
                        }

                        newprice.Note = HttpUtility.HtmlDecode(newprice.Note);
                        if ((newprice.Note != "") && (newprice.Note != price.Note.Split('_')[0]))
                        {
                            price.Note = newprice.Note + ex;
                            ischanged = true;
                        }
                        else if (newprice.Note == "")
                        {
                            price.Note = newprice.Note;
                            ischanged = true;
                        }

                        price.UserID = long.Parse(context.Session["logined_id"].ToString());
                        if (ischanged)
                        {
                            price.LastUpdate = DateTime.Now;
                            //Update Log                                                                                
                            UserObjectsLog.SaveObjectActionLog(long.Parse(context.Session["logined_id"].ToString()), "PriceAreasNew", "Edit", GV.cn, GV.trans);
                            price.Save(LdExpress.GV.cn, LdExpress.GV.trans);
                        }
                        i++;
                    }
                }
            }
        }
        var t = new { UserName = context.Session["logined_user"], Date = DateTime.Now.ToString("dd-MM-yyyy") };
        context.Response.Write(JsonConvert.SerializeObject(t));
    }
    private void UpdatePriceAreaNew(HttpContext context)
    {
        string items = context.Request.Params["items"];
        if (!string.IsNullOrEmpty(items))
        {
            List<LdExpress.PriceAreasNew> udpitems = JsonConvert.DeserializeObject<List<LdExpress.PriceAreasNew>>(items);
            string ids = "";
            ids = string.Join(",", udpitems.Select(q => q.ID));
            DataSet ds = new DataSet();
            string condition = "";
            if (!string.IsNullOrEmpty(ids))
            {
                condition = " and tbl_priceAreasNew.ID in (" + ids + ")";
            }
            else
            {
                context.Response.Write(JsonConvert.SerializeObject("not valid"));
            }
            int nNumOfPages = 0;
            LdExpress.PriceAreasNew.GetList(condition, "", 999, 1, out nNumOfPages, out ds, LdExpress.GV.cn, LdExpress.GV.trans);
            Array arr = udpitems.ToArray();
            //Insert 
            DataSet dscheck = null;
            foreach (PriceAreasNew p in udpitems)
            {
                if (p.ID <= 0 && p.ServiceAreaName.Length > 0)
                {


                    ServiceAreas objSer = new ServiceAreas();
                    objSer.LoadByCode(p.ServiceAreaName, GV.cn, GV.trans);
                    if (objSer.ID > 0)
                    {
                        string ex = "_" + context.Session["logined_user"] + ": " + DateTime.Now.ToString("dd-MM-yyyy");
                        PriceAreasNew obj = new PriceAreasNew();
                        bool isInsertNote = false;
                        if (p.DC20.Length > 0)
                        {
                            obj.DC20 = p.DC20 + ex;
                            isInsertNote = true;
                        }
                        if (p.DC40.Length > 0)
                        {
                            obj.DC40 = p.DC40 + ex;
                            isInsertNote = true;
                        }
                        if (p.HC40.Length > 0)
                        {
                            obj.HC40 = p.HC40 + ex;
                            isInsertNote = true;
                        }
                        if (obj.Validity.Length > 0)
                        {
                            obj.Validity = p.Validity + ex;
                            isInsertNote = true;
                        }
                        if (p.Note.Length > 0)
                            obj.Note = p.Note + ex;
                        else if (isInsertNote)
                            obj.Note = "MBL" + ex;

                        isInsertNote = false;
                        if (p.RF20.Length > 0)
                        {
                            obj.RF20 = p.RF20 + ex;
                            isInsertNote = true;
                        }
                        if (p.RF40.Length > 0)
                        {
                            obj.RF40 = p.RF40 + ex;
                            isInsertNote = true;
                        }
                        if (p.ValidityEx.Length > 0)
                        {
                            obj.ValidityEx = p.ValidityEx + ex;
                            isInsertNote = true;
                        }
                        if (p.NoteEx.Length > 0)
                            obj.NoteEx = p.NoteEx + ex;
                        else if (isInsertNote)
                            obj.NoteEx = "MBL" + ex;


                        obj.ServiceAreaName = p.ServiceAreaName + ex;
                        if (p.PodIncluded.Length > 0)
                            obj.PodIncluded = p.PodIncluded + ex;
                        obj.CarrID = p.CarrID;
                        obj.PolID = p.PolID;
                        obj.ServiceAreaID = objSer.ID;
                        obj.LastUpdate = DateTime.Now;
                        obj.Save(LdExpress.GV.cn, LdExpress.GV.trans);
                    }

                }
            }
            int i = 0;
            if (ds.Tables.Count > 0)
            {
                LdExpress.PriceAreasNew price = new LdExpress.PriceAreasNew();
                LdExpress.PriceAreasNew newprice = new LdExpress.PriceAreasNew();
                string ex = "_" + context.Session["logined_user"] + ": " + DateTime.Now.ToString("dd-MM-yyyy");
                bool ischanged = false;
                foreach (System.Data.DataRow dr in ds.Tables[0].Rows)
                {

                    price = new LdExpress.PriceAreasNew();

                    if (!dr.IsNull("ID")) price.ID = long.Parse(dr["ID"].ToString());
                    if (!dr.IsNull("DC20")) price.DC20 = dr["DC20"].ToString();
                    if (!dr.IsNull("DC40")) price.DC40 = dr["DC40"].ToString();
                    if (!dr.IsNull("HC40")) price.HC40 = dr["HC40"].ToString();
                    if (!dr.IsNull("Validity")) price.Validity = dr["Validity"].ToString();
                    if (!dr.IsNull("ValidityEx")) price.ValidityEx = dr["ValidityEx"].ToString();
                    if (!dr.IsNull("HC40")) price.HC40 = dr["HC40"].ToString();
                    if (!dr.IsNull("RF20")) price.RF20 = dr["RF20"].ToString();
                    if (!dr.IsNull("RF40")) price.RF40 = dr["RF40"].ToString();
                    if (!dr.IsNull("Note")) price.Note = dr["Note"].ToString();
                    if (!dr.IsNull("NoteEx")) price.NoteEx = dr["NoteEx"].ToString();
                    if (!dr.IsNull("ServiceAreaName")) price.ServiceAreaName = dr["ServiceAreaName"].ToString();
                    if (!dr.IsNull("PodIncluded")) price.PodIncluded = dr["PodIncluded"].ToString();
                    if (!dr.IsNull("CarrID")) price.CarrID = long.Parse(dr["CarrID"].ToString());
                    if (!dr.IsNull("PolID")) price.PolID = long.Parse(dr["PolID"].ToString());
                    if (!dr.IsNull("ServiceAreaID")) price.ServiceAreaID = long.Parse(dr["ServiceAreaID"].ToString());
                    if (!dr.IsNull("Sort")) price.Sort = int.Parse(dr["Sort"].ToString());
                    if (!dr.IsNull("UserID")) price.UserID = int.Parse(dr["UserID"].ToString());
                    if (!dr.IsNull("LastUpdate")) price.LastUpdate = DateTime.Parse(dr["LastUpdate"].ToString());

                    //set new value
                    newprice = udpitems.Where(q => q.ID == price.ID).FirstOrDefault();

                    if (newprice != null)
                    {
                        ServiceAreas objSer = new ServiceAreas();
                        objSer.LoadByCode(newprice.ServiceAreaName, GV.cn, GV.trans);
                        if (objSer.ID > 0)
                        {
                            newprice.DC20 = HttpUtility.HtmlDecode(newprice.DC20);
                            if ((newprice.DC20 != "") && (newprice.DC20 != price.DC20.Split('_')[0]))
                            {
                                price.DC20 = newprice.DC20 + ex;
                                ischanged = true;
                            }
                            else if (newprice.DC20 == "")
                            {
                                price.DC20 = newprice.DC20;
                                ischanged = true;
                            }
                            newprice.DC40 = HttpUtility.HtmlDecode(newprice.DC40);
                            if ((newprice.DC40 != "") && (newprice.DC40 != price.DC40.Split('_')[0]))
                            {
                                price.DC40 = newprice.DC40 + ex;
                                ischanged = true;
                            }
                            else if (newprice.DC40 == "")
                            {
                                price.DC40 = newprice.DC40;
                                ischanged = true;
                            }

                            newprice.HC40 = HttpUtility.HtmlDecode(newprice.HC40);
                            if ((newprice.HC40 != "") && (newprice.HC40 != price.HC40.Split('_')[0]))
                            {
                                price.HC40 = newprice.HC40 + ex;
                                ischanged = true;
                            }
                            else if (newprice.HC40 == "")
                            {
                                price.HC40 = newprice.HC40;
                                ischanged = true;
                            }

                            newprice.RF20 = HttpUtility.HtmlDecode(newprice.RF20);
                            if ((newprice.RF20 != "") && (newprice.RF20 != price.RF20.Split('_')[0]))
                            {
                                price.RF20 = newprice.RF20 + ex;
                                ischanged = true;
                            }
                            else if (newprice.RF20 == "")
                            {
                                price.RF20 = newprice.RF20;
                                ischanged = true;
                            }

                            newprice.RF40 = HttpUtility.HtmlDecode(newprice.RF40);
                            if ((newprice.RF40 != "") && (newprice.RF40 != price.RF40.Split('_')[0]))
                            {
                                price.RF40 = newprice.RF40 + ex;
                                ischanged = true;
                            }
                            else if (newprice.RF40 == "")
                            {
                                price.RF40 = newprice.RF40;
                            }
                            newprice.Validity = HttpUtility.HtmlDecode(newprice.Validity);
                            if ((newprice.Validity != "") && (newprice.Validity != price.Validity.Split('_')[0]))
                            {
                                price.Validity = newprice.Validity + ex;
                                ischanged = true;
                            }
                            else if (newprice.Validity == "")
                            {
                                price.Validity = newprice.Validity;
                                ischanged = true;
                            }
                            //Validity Ex
                            newprice.ValidityEx = HttpUtility.HtmlDecode(newprice.ValidityEx);
                            if ((newprice.ValidityEx != "") && (newprice.ValidityEx != price.ValidityEx.Split('_')[0]))
                            {
                                price.ValidityEx = newprice.ValidityEx + ex;
                                ischanged = true;
                            }
                            else if (newprice.ValidityEx == "")
                            {
                                price.ValidityEx = newprice.ValidityEx;
                                ischanged = true;
                            }

                            newprice.Note = HttpUtility.HtmlDecode(newprice.Note);
                            if ((newprice.Note != "") && (newprice.Note != price.Note.Split('_')[0]))
                            {
                                price.Note = newprice.Note + ex;
                                ischanged = true;
                            }
                            else if (newprice.Note == "")
                            {
                                price.Note = newprice.Note;
                                ischanged = true;
                            }
                            //Note Ex
                            newprice.NoteEx = HttpUtility.HtmlDecode(newprice.NoteEx);
                            if ((newprice.NoteEx != "") && (newprice.NoteEx != price.NoteEx.Split('_')[0]))
                            {
                                price.NoteEx = newprice.NoteEx + ex;
                                ischanged = true;
                            }
                            else if (newprice.NoteEx == "")
                            {
                                price.NoteEx = newprice.NoteEx;
                                ischanged = true;
                            }

                            newprice.ServiceAreaName = HttpUtility.HtmlDecode(newprice.ServiceAreaName);
                            if ((newprice.ServiceAreaName != "") && (newprice.ServiceAreaName != price.ServiceAreaName.Split('_')[0]))
                            {
                                price.ServiceAreaName = newprice.ServiceAreaName + ex;
                                ischanged = true;
                                price.ServiceAreaID = objSer.ID;
                            }
                            //else if (newprice.ServiceAreaName == "")
                            //{
                            //    price.ServiceAreaName = newprice.ServiceAreaName;
                            //    ischanged = true;
                            //}

                            newprice.PodIncluded = HttpUtility.HtmlDecode(newprice.PodIncluded);
                            if ((newprice.PodIncluded != "") && (newprice.PodIncluded != price.PodIncluded.Split('_')[0]))
                            {
                                price.PodIncluded = newprice.PodIncluded + ex;
                                ischanged = true;
                            }
                            else if (newprice.PodIncluded == "")
                            {
                                price.PodIncluded = newprice.PodIncluded;
                                ischanged = true;
                            }

                            price.UserID = long.Parse(context.Session["logined_id"].ToString());
                            if (ischanged)
                            {
                                price.LastUpdate = DateTime.Now;
                                //Update Log                                                                                
                                UserObjectsLog.SaveObjectActionLog(long.Parse(context.Session["logined_id"].ToString()), "PriceAreasNew", "Edit", GV.cn, GV.trans);
                                price.Save(LdExpress.GV.cn, LdExpress.GV.trans);
                            }
                            i++;
                        }
                    }
                }
            }
            var t = new { UserName = context.Session["logined_user"], Date = DateTime.Now.ToString("dd-MM-yyyy") };
            context.Response.Write(JsonConvert.SerializeObject(t));
        }
    }
    private void UpdateTruckerPrice(HttpContext context)
    {
        string items = context.Request.Params["items"];
        if (!string.IsNullOrEmpty(items))
        {
            List<LdExpress.TruckerPrice> udpitems = JsonConvert.DeserializeObject<List<LdExpress.TruckerPrice>>(items);
            foreach (TruckerPrice newPrice in udpitems)
            {
                //Load Old Data
                TruckerPrice price = new TruckerPrice();
                //TruckerPrice newPrice = new TruckerPrice();
                price.ID = newPrice.ID;
                price.Load(GV.cn, GV.trans);
                string ex = "_" + context.Session["logined_user"] + ": " + DateTime.Now.ToString("dd-MM-yyyy");
                bool ischanged = false;
                //set new value
                //newPrice = udpitems.Where(q => q.ID == item.ID).FirstOrDefault();

                if (newPrice != null)
                {
                    //Cont20
                    bool updateDoPrice = false;

                    newPrice.Cont20 = HttpUtility.HtmlDecode(newPrice.Cont20);
                    if ((newPrice.Cont20 != "") && (newPrice.Cont20 != price.Cont20.Split('_')[0]))
                    {
                        price.Cont20 = newPrice.Cont20 + ex;
                        updateDoPrice = true;
                        ischanged = true;
                        price.LastUdate20 = DateTime.Now;
                    }
                    else if (newPrice.Cont20 == "")
                    {
                        price.Cont20 = newPrice.Cont20;
                        ischanged = true;
                    }
                    //Tons20
                    newPrice.Tons20 = HttpUtility.HtmlDecode(newPrice.Tons20);
                    if ((newPrice.Tons20 != "") && (newPrice.Tons20 != price.Tons20.Split('_')[0]))
                    {
                        price.Tons20 = newPrice.Tons20 + ex;
                        ischanged = true;
                    }
                    else if (newPrice.Tons20 == "")
                    {
                        price.Tons20 = newPrice.Tons20;
                        ischanged = true;
                    }
                    //Kms20
                    newPrice.Kms20 = HttpUtility.HtmlDecode(newPrice.Kms20);
                    if ((newPrice.Kms20 != "") && (newPrice.Kms20 != price.Kms20.Split('_')[0]))
                    {
                        price.Kms20 = newPrice.Kms20 + ex;
                        ischanged = true;
                    }
                    else if (newPrice.Kms20 == "")
                    {
                        price.Kms20 = newPrice.Kms20;
                        ischanged = true;
                    }

                    //Doprice20
                    if (updateDoPrice)
                    {
                        price.DoPrice20 = GeneralSetting.GetValueByCode("DoPrice", GV.cn, GV.trans) + ex;
                    }
                    else
                    {
                        newPrice.DoPrice20 = HttpUtility.HtmlDecode(newPrice.DoPrice20);
                        if ((newPrice.DoPrice20 != "") && (newPrice.DoPrice20 != price.DoPrice20.Split('_')[0]))
                        {
                            price.DoPrice20 = newPrice.DoPrice20 + ex;
                            ischanged = true;
                        }
                        else if (newPrice.DoPrice20 == "")
                        {
                            price.DoPrice20 = newPrice.DoPrice20;
                            ischanged = true;
                        }
                    }
                    //Note20
                    newPrice.Note20 = HttpUtility.HtmlDecode(newPrice.Note20);
                    if ((newPrice.Note20 != "") && (newPrice.Note20 != price.Note20.Split('_')[0]))
                    {
                        price.Note20 = newPrice.Note20 + ex;
                        ischanged = true;
                    }
                    else if (newPrice.Note20 == "")
                    {
                        price.Note20 = newPrice.Note20;
                        ischanged = true;
                    }
                    /*---------------Cont 40 -------------------------*/
                    //Cont40

                    updateDoPrice = false;
                    newPrice.Cont40 = HttpUtility.HtmlDecode(newPrice.Cont40);
                    if ((newPrice.Cont40 != "") && (newPrice.Cont40 != price.Cont40.Split('_')[0]))
                    {
                        price.Cont40 = newPrice.Cont40 + ex;
                        updateDoPrice = true;
                        ischanged = true;
                        price.LastUdate20 = DateTime.Now;
                    }
                    else if (newPrice.Cont40 == "")
                    {
                        price.Cont40 = newPrice.Cont40;
                        ischanged = true;
                    }
                    //Tons40
                    newPrice.Tons40 = HttpUtility.HtmlDecode(newPrice.Tons40);
                    if ((newPrice.Tons40 != "") && (newPrice.Tons40 != price.Tons40.Split('_')[0]))
                    {
                        price.Tons40 = newPrice.Tons40 + ex;
                        ischanged = true;
                    }
                    else if (newPrice.Tons40 == "")
                    {
                        price.Tons40 = newPrice.Tons40;
                        ischanged = true;
                    }
                    //Kms40
                    newPrice.Kms40 = HttpUtility.HtmlDecode(newPrice.Kms40);
                    if ((newPrice.Kms40 != "") && (newPrice.Kms40 != price.Kms40.Split('_')[0]))
                    {
                        price.Kms40 = newPrice.Kms40 + ex;
                        ischanged = true;
                    }
                    else if (newPrice.Kms40 == "")
                    {
                        price.Kms40 = newPrice.Kms40;
                        ischanged = true;
                    }
                    //Doprice40
                    if (updateDoPrice)
                    {
                        price.DoPrice40 = GeneralSetting.GetValueByCode("DoPrice", GV.cn, GV.trans) + ex;
                    }
                    else
                    {
                        newPrice.DoPrice40 = HttpUtility.HtmlDecode(newPrice.DoPrice40);
                        if ((newPrice.DoPrice40 != "") && (newPrice.DoPrice40 != price.DoPrice40.Split('_')[0]))
                        {
                            price.DoPrice40 = newPrice.DoPrice40 + ex;
                            ischanged = true;
                        }
                        else if (newPrice.DoPrice40 == "")
                        {
                            price.DoPrice40 = newPrice.DoPrice40;
                            ischanged = true;
                        }
                    }
                    //Note40
                    newPrice.Note40 = HttpUtility.HtmlDecode(newPrice.Note40);
                    if ((newPrice.Note40 != "") && (newPrice.Note40 != price.Note40.Split('_')[0]))
                    {
                        price.Note40 = newPrice.Note40 + ex;
                        ischanged = true;
                    }
                    else if (newPrice.Note40 == "")
                    {
                        price.Note40 = newPrice.Note40;
                        ischanged = true;
                    }

                    if (ischanged)
                    {
                        UserObjectsLog.SaveObjectActionLog(long.Parse(context.Session["logined_id"].ToString()), "TruckerPrice", "Edit", GV.cn, GV.trans);
                        price.Save(LdExpress.GV.cn, LdExpress.GV.trans);
                    }
                }
            }
            var t = new { UserName = context.Session["logined_user"], Date = DateTime.Now.ToString("dd-MM-yyyy") };
            context.Response.Write(JsonConvert.SerializeObject(t));
        }
    }
    public bool IsReusable
    {
        get
        {
            return false;
        }
    }

}